<template>
  <div class="playlist-sidebar">
    <div class="sidebar-header">
      <h3>播放列表</h3>
      <button @click="$router.back()" class="close-btn">×</button>
    </div>
    <ul class="song-list">
      <li
          v-for="(song, index) in playlist"
          :key="index"
          @click="selectTrack(index)"
          :class="{ active: currentIndex === index }"
      >
        <span class="track-number">{{ index + 1 }}</span>
        <div class="track-info">
          <span class="title">{{ song.name }}</span>
          <span class="artist">{{ song.artist }}</span>
        </div>
        <span class="duration">3:45</span>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: {
    playlist: Array,
    currentIndex: Number
  },
  methods: {
    selectTrack(index) {
      this.$emit('track-selected', index)
      this.$router.back()
    }
  }
}
</script>

<style scoped>
.playlist-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  padding: 20px;
  z-index: 100;
  overflow-y: auto;
  box-shadow: -5px 0 15px rgba(0, 0, 0, 0.5);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #333;
}

.close-btn {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
}

.song-list {
  list-style: none;
  padding: 0;
}

.song-list li {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: background 0.2s;
}

.song-list li:hover {
  background: rgba(255, 255, 255, 0.05);
}

.song-list li.active {
  color: #1db954;
}

.track-number {
  width: 30px;
  text-align: center;
  color: #666;
  font-size: 14px;
}

.track-info {
  flex: 1;
  margin: 0 10px;
  overflow: hidden;
}

.title {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.artist {
  font-size: 12px;
  color: #aaa;
}

.duration {
  font-size: 12px;
  color: #666;
}
</style>